package com.sunlands.deskmate.repository;

import com.sunlands.deskmate.domain.MessageDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author shixiaopeng
 */
@Repository
public interface MessageRepository extends JpaRepository<MessageDO, Integer> {

    MessageDO findAllByUserIdAndBusinessIdAndType(Integer userId, String businessId, String type);

    MessageDO findFirstByUserIdAndType(Integer userId, String type);

    MessageDO findFirstByUserIdAndBusinessId(Integer userId, String businessId);

    MessageDO findFirstByUserIdAndBusinessIdAndTypeIsNot(Integer userId, String businessId, String type);

    List<MessageDO> findAllByBusinessIdAndType(String businessId, String type);

    List<MessageDO> findAllByUserIdAndIsReadOrderByUpdateDateTimeDesc(Integer userId, Boolean isRead);

    @Query(value = "select * from tz_message where type like ?1 order by business_id, user_id,type ", nativeQuery = true)
    List<MessageDO> findBySql(String type);
}
